package com.company.观察者模式;

import java.util.ArrayList;
import java.util.List;

/**
 * 观察者所观察的目标对象
 */
public abstract class Subject {
    private List<Observer> observerList = new ArrayList<>();

    public void addObserver(Observer observer){
        observerList.add(observer);
    }
    public void removeObserver(Observer observer){
        observerList.remove(observer);
    }
    //目标对象发生变化时，传递的参数
    protected void notifyAllObservers(Object arg){
        for (Observer ob: observerList){
            ob.update(arg);
        }
    }
}
